home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / GeometryTest / Geometries.c next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  32.8 KB  |  1,338 lines  |  [TEXT/MPCC]

  1. /******************************************************************************
  2.  **                                                                             **
  3.  **     Module:        Geometrys.c                                                  **
  4.  **                                                                          **
  5.  **                                                                          **
  6.  **     Purpose:                                                              **
  7.  **                                                                          **
  8.  **                                                                          **
  9.  **                                                                          **
  10.  **     Copyright (C) 1992-1995 Apple Computer, Inc.  All rights reserved.     **
  11.  **                                                                          **
  12.  **                                                                          **
  13.  **     Change Log:                                                             **
  14.  **                                                                          **
  15.  **                                                                          **
  16.  *****************************************************************************/
  17. #include <stdlib.h>
  18.  
  19. #include "QD3D.h"
  20. #include "QD3DGeometry.h"
  21. #include "QD3DTransform.h"
  22. #include "QD3DGroup.h"
  23. #include "QD3DSet.h"
  24. #include "QD3DShader.h"
  25. #include "QD3DDrawContext.h"
  26.  
  27. #include "GTShell.h"
  28. #include "AttributeSet_Lib.h"
  29. #include "QD3DStyle.h"
  30.  
  31. #include "QD3DMath.h"
  32. #include "Geometries.h"
  33.  
  34. TextureRec    gTextureEntries[8];
  35.  
  36.  
  37. /******************************************************************************
  38.  **                                                                             **
  39.  **                                    Defines                                     **
  40.  **                                                                             **
  41.  *****************************************************************************/
  42.  
  43.  
  44. #define UVERTICES    11            /* For Scene object */
  45. #define VVERTICES    11
  46. #define FULLMESH    0            /* Set this to 1 to show a bug in mesh attrib. inheritance (??) */
  47.  
  48. /******************************************************************************
  49.  **                                                                             **
  50.  **                            Local Declarations                                 **
  51.  **                                                                             **
  52.  *****************************************************************************/
  53.  
  54. static TQ3GroupObject    BuildBox(
  55.     void);
  56.         
  57. static TQ3GroupObject    BuildGeneralPolygon(
  58.     void);
  59.     
  60. static TQ3GroupObject    BuildLine(
  61.     void);
  62.     
  63. static TQ3GroupObject    BuildMarker(
  64.     void);
  65.     
  66. static TQ3GroupObject    BuildNURBCurve(
  67.     void);
  68.     
  69. static TQ3GroupObject    BuildNURBPatch(
  70.     void);
  71.     
  72. static TQ3GroupObject    BuildPoint(
  73.     void);
  74.     
  75. static TQ3GroupObject    BuildPolygon(
  76.     void);
  77.     
  78. static TQ3GroupObject    BuildPolyLine(
  79.     void);
  80.     
  81. static TQ3GroupObject    BuildMesh(
  82.     void);
  83.     
  84. static TQ3GroupObject    BuildCursor(
  85.     void);
  86.     
  87. static TQ3GroupObject    BuildTriangle(
  88.     void);
  89.     
  90. static TQ3GroupObject    BuildTriGrid(
  91.     void);
  92.     
  93. static TQ3GroupObject BuildScene(
  94.     void);
  95.  
  96. /******************************************************************************
  97.  **                                                                             **
  98.  **                            API Routines                                     **
  99.  **                                                                             **
  100.  *****************************************************************************/
  101.  
  102. /*===========================================================================*\
  103.  *
  104.  *    Routine:    BuildGeometry()
  105.  *
  106.  *    Comments:    
  107.  *
  108. \*===========================================================================*/
  109.     
  110. TQ3GroupObject BuildGeometry(
  111.     int type)
  112. {
  113.     TQ3GroupObject    model = NULL;
  114.  
  115.     switch (type) {
  116.         case iMarker:
  117.             model = BuildMarker();
  118.             break;
  119.         case iPoint:
  120.             model = BuildPoint();
  121.             break;
  122.         case iLine:
  123.             model = BuildLine();
  124.             break;
  125.         case iPolyline:
  126.             model = BuildPolyLine();
  127.             break;
  128.         case iTriangle:
  129.             model = BuildTriangle();
  130.             break;
  131.         case iPolygon:
  132.             model = BuildPolygon();
  133.             break;
  134.         case iGeneralPolygon:
  135.             model = BuildGeneralPolygon();
  136.             break;
  137.         case iTrigrid:
  138.             model = BuildTriGrid();
  139.             break;
  140.         case iBox:
  141.             model = BuildBox();
  142.             break;
  143.         case iMesh:
  144. //            model = BuildCursor();
  145.             model = BuildMesh();
  146.             break;
  147.         case iNurbCurve:
  148.             model = BuildNURBCurve();
  149.             break;
  150.         case iNurbPatch:
  151.             model = BuildNURBPatch();
  152.             break;
  153.     }
  154.     
  155.     return (model);
  156.     
  157. }
  158.  
  159. /******************************************************************************
  160.  **                                                                             **
  161.  **                            Local Routines                                     **
  162.  **                                                                             **
  163.  *****************************************************************************/
  164.  
  165. /*===========================================================================*\
  166.  *
  167.  *    Routine:    BuildMarker()
  168.  *
  169.  *
  170. \*===========================================================================*/
  171.  
  172. static TQ3GroupObject BuildMarker(
  173.     void)
  174. {
  175.     TQ3GroupObject        model;
  176.     TQ3MarkerData        markerData;
  177.     TQ3GeometryObject    marker;
  178.     TQ3ColorRGB            markerColor;
  179.  
  180.  
  181.     TQ3Bitmap            *bitmapPtr = &markerData.bitmap;
  182.     unsigned char        imageData[] = {
  183.                             0x7E, 0x3C, 0x3C, 0x66, 0x7E, 0x7C, 0x18,
  184.                             0x60, 0x60, 0x66, 0x66, 0x60, 0x66, 0x18,
  185.                             0x7C, 0x3C, 0x60, 0x7E, 0x7C, 0x66, 0x18,
  186.                             0x60, 0x06, 0x60, 0x66, 0x60, 0x7C, 0x18,
  187.                             0x60, 0x06, 0x66, 0x66, 0x60, 0x66, 0x00,
  188.                             0x7E, 0x3C, 0x3C, 0x66, 0x7E, 0x66, 0x18
  189.                         };
  190.     
  191.     Q3Point3D_Set(&markerData.location, 0, 1, 1);
  192.     markerData.xOffset    = -28;
  193.     markerData.yOffset    = -3;
  194.     markerData.markerAttributeSet = Q3AttributeSet_New();
  195.     
  196.     markerColor.r = 0.8;
  197.     markerColor.g = 0.2;
  198.     markerColor.b = 0.6;
  199.     AttributeSet_AddDiffuseColor(markerData.markerAttributeSet, &markerColor);
  200.  
  201.  
  202.     bitmapPtr->image    = imageData;
  203.     bitmapPtr->width    = 56;
  204.     bitmapPtr->height    = 6;
  205.     bitmapPtr->rowBytes    = 7;
  206.     bitmapPtr->bitOrder    = kQ3EndianBig;
  207.     
  208.     marker = Q3Marker_New(&markerData);
  209.     model = Q3OrderedDisplayGroup_New();
  210.     
  211.     if (marker != NULL) {
  212.         Q3Group_AddObject(model, marker);    
  213.     
  214.         Q3Object_Dispose(marker);
  215.     }
  216.     
  217.     Q3Object_Dispose(markerData.markerAttributeSet);
  218.  
  219.     return (model);    
  220. }
  221.  
  222.  
  223. /*===========================================================================*\
  224.  *
  225.  *    Routine:    BuildPoint()
  226.  *
  227.  *    Comments:    
  228.  *
  229. \*===========================================================================*/
  230.  
  231. static TQ3GroupObject BuildPoint(
  232.     void)
  233. {
  234.     TQ3GroupObject        model;
  235.     TQ3PointData            pointData;
  236.     TQ3GeometryObject    pointThang;
  237.     TQ3ColorRGB            pointColor;
  238.     
  239.     model = Q3OrderedDisplayGroup_New();
  240.  
  241.     Q3Point3D_Set(&pointData.point, 1, 1, 1);
  242.     pointData.pointAttributeSet = NULL;
  243.     
  244.     pointData.pointAttributeSet = Q3AttributeSet_New();
  245.     
  246.     
  247.     Q3ColorRGB_Set(&pointColor, 0.0, 1.0, 0.0);
  248.     AttributeSet_AddDiffuseColor(pointData.pointAttributeSet, &pointColor);
  249.  
  250.     pointThang = Q3Point_New(&pointData);
  251.     if (pointThang != NULL) {
  252.         Q3Group_AddObject(model, pointThang);
  253.         Q3Object_Dispose(pointThang);
  254.     }        
  255.     Q3Object_Dispose(pointData.pointAttributeSet);
  256.     
  257.     return (model);    
  258.  
  259. }
  260.  
  261. /*===========================================================================*\
  262.  *
  263.  *    Routine:    BuildLine()
  264.  *
  265.  *    Comments:    
  266.  *
  267. \*===========================================================================*/
  268.     
  269. static TQ3GroupObject BuildLine(
  270.     void)
  271. {
  272.     TQ3ColorRGB            lineColor;
  273.     TQ3GroupObject        model;
  274.     TQ3LineData            lineData;
  275.     TQ3GeometryObject    lineThang;
  276.  
  277.     lineData.lineAttributeSet = Q3AttributeSet_New();
  278.     lineColor.r = 0.3;
  279.     lineColor.g = 0.9;
  280.     lineColor.b = 0.9;
  281.     AttributeSet_AddDiffuseColor(lineData.lineAttributeSet, &lineColor);
  282.     
  283. #define DO_TEST_LINE 1
  284. #if DO_TEST_LINE
  285.     lineData.vertices[0].point.x = -1.0;
  286.     lineData.vertices[0].point.y =  0.0;
  287.     lineData.vertices[0].point.z =  0.0;
  288.     lineData.vertices[0].attributeSet = NULL;
  289.     
  290.     lineData.vertices[1].point.x =  1.0;
  291.     lineData.vertices[1].point.y =  0.0;;
  292.     lineData.vertices[1].point.z =  0.0;;
  293.     lineData.vertices[1].attributeSet = NULL;
  294. #else
  295.     lineData.vertices[0].point.x = -1.0;
  296.     lineData.vertices[0].point.y = -0.5;
  297.     lineData.vertices[0].point.z = -0.25;
  298.     lineData.vertices[0].attributeSet = NULL;
  299.     
  300.     lineData.vertices[1].point.x =  2.0;
  301.     lineData.vertices[1].point.y =  1.5;
  302.     lineData.vertices[1].point.z =  2.25;
  303.     lineData.vertices[1].attributeSet = NULL;
  304. #endif  /*  DO_TEST_LINE  */
  305. #undef DO_TEST_LINE
  306.  
  307.     lineThang = Q3Line_New(&lineData);
  308.     
  309.     model = Q3OrderedDisplayGroup_New();
  310.     
  311.     Q3Group_AddObject(model, lineThang);    
  312.  
  313.     Q3Object_Dispose(lineData.lineAttributeSet);
  314.     Q3Object_Dispose(lineThang);
  315.     
  316.     return (model);    
  317. }
  318.  
  319. /*===========================================================================*\
  320.  *
  321.  *    Routine:    BuildPolyLine()
  322.  *
  323.  *    Comments:    
  324.  *
  325. \*===========================================================================*/
  326.     
  327. static TQ3GroupObject BuildPolyLine(
  328.     void)
  329. {
  330.     TQ3ColorRGB            polyLineColor;
  331.  
  332.     TQ3GroupObject        model;
  333.     TQ3PolyLineData        polyLineData;
  334.     TQ3GeometryObject    polyLineThang;
  335.     static TQ3Vertex3D    points[4] = {
  336.                             {{ -1.0, -0.5, -0.25 }, NULL },
  337.                             {{ -0.5,  1.5,  0.45 }, NULL },
  338.                             {{  0.0,  0.0,  0.0  }, NULL },
  339.                             {{  1.5,  1.5,  1.0  }, NULL }
  340.                         };
  341.  
  342.     
  343.     polyLineData.numVertices             = 4;
  344.     polyLineData.vertices                 = points;
  345.     polyLineData.segmentAttributeSet     = malloc(3 * sizeof(TQ3AttributeSet));
  346.     
  347.     {
  348.         unsigned long     i;
  349.         TQ3ColorRGB        segmentColor;
  350.         
  351.         segmentColor.r = 1.0;
  352.         segmentColor.g = 0.0;
  353.         segmentColor.b = 0.2;
  354.         
  355.         for (i = 0; i < polyLineData.numVertices - 1; i++) {
  356.             polyLineData.segmentAttributeSet[i] = NULL;
  357.         }
  358.         
  359.         polyLineData.segmentAttributeSet[1] = Q3AttributeSet_New();
  360.         
  361.         AttributeSet_AddDiffuseColor(polyLineData.segmentAttributeSet[1], 
  362.                                        &segmentColor);
  363.  
  364.     }            
  365.     
  366.     polyLineData.polyLineAttributeSet = NULL;
  367.  
  368.  
  369.     polyLineData.polyLineAttributeSet = Q3AttributeSet_New();
  370.     polyLineColor.r = 0.4;
  371.     polyLineColor.g = 0.2;
  372.     polyLineColor.b = 0.9;
  373.     AttributeSet_AddDiffuseColor(polyLineData.polyLineAttributeSet, &polyLineColor);
  374.  
  375.     polyLineThang = Q3PolyLine_New(&polyLineData);
  376.     
  377.     model = Q3OrderedDisplayGroup_New();
  378.     Q3Group_AddObject(model, polyLineThang);    
  379.  
  380.  
  381.     Q3Object_Dispose(polyLineData.polyLineAttributeSet);
  382.     Q3Object_Dispose(polyLineData.segmentAttributeSet[1]);
  383.     free(polyLineData.segmentAttributeSet);
  384.     Q3Object_Dispose(polyLineThang);
  385.     
  386.     return (model);
  387. }
  388.  
  389.  
  390. /*===========================================================================*\
  391.  *
  392.  *    Routine:    BuildTriangle()
  393.  *
  394.  *    Comments:    
  395.  *
  396. \*===========================================================================*/
  397.  
  398. static TQ3GroupObject BuildTriangle(
  399.     void)
  400. {
  401.     TQ3ColorRGB            triangleColor;
  402.  
  403.     TQ3GroupObject        model;
  404.     TQ3TriangleData        triangleData;
  405.     TQ3GeometryObject    triangleThang;
  406.     static TQ3Vertex3D    vertices[3] = {
  407.                             { { -1.0, -0.5, -0.25 }, NULL },
  408.                             { {  0.0,  0.0,  0.0  }, NULL },
  409.                             { { -0.5,  1.5,  0.45 }, NULL },
  410.                         };
  411.  
  412.     triangleData.vertices[0] = vertices[0];
  413.     triangleData.vertices[1] = vertices[1];
  414.     triangleData.vertices[2] = vertices[2];
  415.     
  416.     triangleData.triangleAttributeSet = Q3AttributeSet_New();
  417.     triangleColor.r = 0.8;
  418.     triangleColor.g = 0.5;
  419.     triangleColor.b = 0.2;
  420.     AttributeSet_AddDiffuseColor(triangleData.triangleAttributeSet, &triangleColor);
  421.  
  422.     triangleData.vertices[0].attributeSet = Q3AttributeSet_New();
  423.     triangleData.vertices[1].attributeSet = Q3AttributeSet_New();
  424.     triangleData.vertices[2].attributeSet = Q3AttributeSet_New();
  425.     triangleColor.r = 1.0;
  426.     triangleColor.g = 0.0;
  427.     triangleColor.b = 0.0;
  428.     AttributeSet_AddDiffuseColor(triangleData.vertices[0].attributeSet, &triangleColor);
  429.     triangleColor.r = 0.0;
  430.     triangleColor.g = 1.0;
  431.     triangleColor.b = 0.0;
  432.     AttributeSet_AddDiffuseColor(triangleData.vertices[1].attributeSet, &triangleColor);
  433.     triangleColor.r = 0.0;
  434.     triangleColor.g = 0.0;
  435.     triangleColor.b = 1.0;
  436.     AttributeSet_AddDiffuseColor(triangleData.vertices[2].attributeSet, &triangleColor);
  437.  
  438.     triangleThang = Q3Triangle_New(&triangleData);
  439.     
  440.     model = Q3OrderedDisplayGroup_New();
  441.  
  442.     if (triangleThang != NULL) {
  443.         Q3Group_AddObject(model, triangleThang);    
  444.     
  445.         Q3Object_Dispose(triangleThang);
  446.     }
  447.     
  448.     Q3Object_Dispose(triangleData.vertices[0].attributeSet);
  449.     Q3Object_Dispose(triangleData.vertices[1].attributeSet);
  450.     Q3Object_Dispose(triangleData.vertices[2].attributeSet);
  451.     Q3Object_Dispose(triangleData.triangleAttributeSet);
  452.  
  453.     return (model);    
  454. }
  455.  
  456. /*===========================================================================*\
  457.  *
  458.  *    Routine:    BuildPolygon()
  459.  *
  460.  *    Comments:    
  461.  *
  462. \*===========================================================================*/
  463.  
  464. static TQ3GroupObject BuildPolygon(
  465.     void)
  466. {
  467.     TQ3GroupObject        model;
  468.     TQ3PolygonData        polygonData;
  469.     TQ3GeometryObject    polygonThang;
  470.     static TQ3Vertex3D    vertices[4] = {
  471.                             { { -10.0, 1, 0 }, NULL },
  472.                             { { -1.0,  -1.0,  0.0  }, NULL },
  473.                             { { 1,  -1.0,  0 }, NULL },
  474.                             { { 1.0,  1, 0 }, NULL },
  475.                         };
  476.     
  477.     polygonData.numVertices         = 4;
  478.     polygonData.vertices             = vertices;
  479.     polygonData.polygonAttributeSet     = NULL;
  480.     
  481.     polygonThang = Q3Polygon_New(&polygonData);
  482.     
  483.     model = Q3OrderedDisplayGroup_New();
  484.     
  485.     Q3Group_AddObject(model, polygonThang);    
  486.     
  487.     Q3Object_Dispose(polygonThang);
  488.     
  489.     return (model);    
  490.  
  491. }
  492.  
  493.  
  494. /*===========================================================================*\
  495.  *
  496.  *    Routine:    BuildGeneralPolygon()
  497.  *
  498.  *    Comments:    
  499.  *
  500. \*===========================================================================*/
  501.  
  502. static TQ3GroupObject BuildGeneralPolygon(
  503.     void)
  504. {
  505.     TQ3GroupObject                    model;
  506.     TQ3GeneralPolygonData            genPolyData;
  507.     TQ3GeneralPolygonContourData        contours[2];
  508.     TQ3GeometryObject                polygonThang;
  509. #if 0
  510.     static TQ3Vertex3D        vertices1[4] = {
  511.                                 { { -1.0, -0.5, -0.25 }, NULL },
  512.                                 { {  0.0,  0.0, -0.25 }, NULL },
  513.                                 { { -0.5,  1.5, -0.25 }, NULL },
  514.                                 { { -1.0,  2.5, -0.25 }, NULL }
  515.                             };
  516.                         
  517.     static TQ3Vertex3D        vertices2[4] = {
  518.                                 { { -0.7, -0.4, -0.25 }, NULL },
  519.                                 { {  0.2,  0.2, -0.25 }, NULL },
  520.                                 { { -0.3,  1.2, -0.25 }, NULL },
  521.                                 { { -1.0,  2.5, -0.25 }, NULL }
  522.                             };
  523. #else
  524.     static TQ3Vertex3D        vertices1[3] = {
  525.                                 { { -1.0,  0.0, 0.0 }, NULL },
  526.                                 { {  1.0,  0.0, 0.0 }, NULL },
  527.                                 { {  0.0,  1.7, 0.0 }, NULL }
  528.                             };
  529.                         
  530.     static TQ3Vertex3D        vertices2[3] = {
  531.                                 { { -1.0,  0.4, 0.0 }, NULL },
  532.                                 { {  1.0,  0.4, 0.0 }, NULL },
  533.                                 { {  0.0,  2.1, 0.0 }, NULL }
  534.                             };
  535. #endif
  536.     TQ3ColorRGB                color;
  537.  
  538.     
  539.     contours[0].numVertices         = 3;
  540.     contours[0].vertices             = vertices1;
  541.     
  542.     contours[1].numVertices         = 3;
  543.     contours[1].vertices             = vertices2;
  544.  
  545.     genPolyData.numContours                 = 2;
  546.     genPolyData.contours                     = contours;
  547.     genPolyData.shapeHint                    = kQ3GeneralPolygonShapeHintComplex;
  548.     genPolyData.generalPolygonAttributeSet     = Q3AttributeSet_New();
  549.     
  550.     color.r = 1.0; color.g = 1.0; color.b = 1.0;
  551.     AttributeSet_AddDiffuseColor(genPolyData.generalPolygonAttributeSet, &color);
  552.  
  553.     vertices1[1].attributeSet = Q3AttributeSet_New();
  554.     vertices1[2].attributeSet = Q3AttributeSet_New();
  555.     
  556.     color.r = 0.0; color.g = 0.0; color.b = 1.0;
  557.     AttributeSet_AddDiffuseColor(vertices1[1].attributeSet, &color);
  558.     
  559.     color.r = 0.0; color.g = 1.0; color.b = 1.0;
  560.     AttributeSet_AddDiffuseColor(vertices1[2].attributeSet, &color);
  561.     
  562.     vertices2[0].attributeSet = Q3AttributeSet_New();
  563.     vertices2[2].attributeSet = Q3AttributeSet_New();
  564.     
  565.     color.r = 1.0; color.g = 0.0; color.b = 1.0;
  566.     AttributeSet_AddDiffuseColor(vertices2[0].attributeSet, &color);
  567.     
  568.     color.r = 1.0; color.g = 1.0; color.b = 0.0;
  569.     AttributeSet_AddDiffuseColor(vertices2[2].attributeSet, &color);
  570.     
  571.     polygonThang = Q3GeneralPolygon_New(&genPolyData);
  572.     
  573.     model = Q3OrderedDisplayGroup_New();
  574.     
  575.     if (polygonThang != NULL) {
  576.         Q3Group_AddObject(model, polygonThang);    
  577.         Q3Object_Dispose(polygonThang);
  578.     }
  579.  
  580.     Q3Object_Dispose(vertices1[1].attributeSet);
  581.     Q3Object_Dispose(vertices1[2].attributeSet);
  582.     Q3Object_Dispose(vertices2[0].attributeSet);
  583.     Q3Object_Dispose(vertices2[2].attributeSet);
  584.     Q3Object_Dispose(genPolyData.generalPolygonAttributeSet);
  585.     
  586.     return (model);    
  587. }
  588.  
  589.  
  590. /*===========================================================================*\
  591.  *
  592.  *    Routine:    BuildTriGrid()
  593.  *
  594.  *    Comments:    
  595.  *
  596. \*===========================================================================*/
  597.     
  598. static TQ3GroupObject BuildTriGrid(
  599.     void)
  600. {
  601.     TQ3ColorRGB            triGridColor;
  602.  
  603.     TQ3GroupObject        model;
  604.     TQ3TriGridData        triGridData;
  605.     TQ3GeometryObject    triGridThang;
  606.     unsigned long        numFacets, i;
  607.  
  608.     static TQ3Vertex3D    vertices[12] = {
  609.                             { { -1.0,  -1.0,  0.0 }, NULL },
  610.                             { { -0.5, -1.0,  0.0 }, NULL },
  611.                             { {  0.0,  -1.0,  0.1 }, NULL },
  612.                             { {  0.2, -1.3,  0.2 }, NULL },
  613.     
  614.                             { { -1.0,  0.0,  0.0 }, NULL },
  615.                             { { -0.5, 0.0,  0.3 }, NULL },
  616.                             { {  0.0,  0.2,  0.0 }, NULL },
  617.                             { {  0.5, 0.0,  0.0 }, NULL },
  618.                         
  619.                             { { -1.0,  1.0,  1.0 }, NULL },
  620.                             { { -0.5, 1.0,  0.0 }, NULL },
  621.                             { {  0.0,  1.0,  0.0 }, NULL },
  622.                             { {  0.7, 1.0,  0.5 }, NULL },
  623.                         };
  624.     
  625.     triGridData.numRows = 3;
  626.     triGridData.numColumns = 4;
  627.     triGridData.vertices  = (TQ3Vertex3D *)malloc(12 * sizeof(TQ3Vertex3D));
  628.     triGridData.vertices[0] = vertices[0];
  629.     triGridData.vertices[1] = vertices[1];
  630.     triGridData.vertices[2] = vertices[2];
  631.     triGridData.vertices[3] = vertices[3];
  632.     triGridData.vertices[4] = vertices[4];
  633.     triGridData.vertices[5] = vertices[5];
  634.     triGridData.vertices[6] = vertices[6];
  635.     triGridData.vertices[7] = vertices[7];
  636.     triGridData.vertices[8] = vertices[8];
  637.     triGridData.vertices[9] = vertices[9];
  638.     triGridData.vertices[10] = vertices[10];
  639.     triGridData.vertices[11] = vertices[11];
  640.  
  641.     triGridData.facetAttributeSet = NULL;
  642.     
  643.     triGridData.triGridAttributeSet = Q3AttributeSet_New();
  644.     
  645.     triGridColor.r = 0.8;
  646.     triGridColor.g = 0.7;
  647.     triGridColor.b = 0.3;
  648.  
  649.     AttributeSet_AddDiffuseColor(triGridData.triGridAttributeSet, &triGridColor);
  650.     
  651.     numFacets = (triGridData.numRows - 1) *  (triGridData.numColumns - 1) *  2 ;
  652.     triGridData.facetAttributeSet = malloc(numFacets * sizeof(TQ3AttributeSet));
  653.     
  654.     for (i = 0; i < numFacets; i++) {
  655.         triGridData.facetAttributeSet[i] = NULL;
  656.     }
  657.     
  658.     triGridColor.r = 1.0;
  659.     triGridColor.g = 0.0;
  660.     triGridColor.b = 0.5;
  661.                                               
  662.     triGridData.facetAttributeSet[5] = Q3AttributeSet_New();                        
  663.     AttributeSet_AddDiffuseColor(triGridData.facetAttributeSet[5], &triGridColor);
  664.     
  665.     triGridThang = Q3TriGrid_New(&triGridData);
  666.     
  667.     model = Q3OrderedDisplayGroup_New();
  668.     
  669.     Q3Group_AddObject(model, triGridThang);    
  670.     
  671.     Q3Object_Dispose(triGridThang);
  672.     Q3Object_Dispose(triGridData.triGridAttributeSet);
  673.     Q3Object_Dispose(triGridData.facetAttributeSet[5]);
  674.     free(triGridData.facetAttributeSet);
  675.  
  676.     return (model);    
  677. }
  678.  
  679.  
  680.  
  681. /*===========================================================================*\
  682.  *
  683.  *    Routine:    BuildBox()
  684.  *
  685.  *    Comments:    
  686.  *
  687. \*===========================================================================*/
  688.     
  689. static TQ3GroupObject BuildBox(
  690.     void)
  691. {
  692.     TQ3ColorRGB            faceColor;
  693.  
  694.     TQ3GroupObject        model;
  695.     TQ3BoxData            boxData;
  696.     TQ3GeometryObject    boxThang;
  697.     
  698.     Q3Point3D_Set(&boxData.origin, 0, 0, 0);
  699.     Q3Vector3D_Set(&boxData.orientation, 0, 1, 0);
  700.     Q3Vector3D_Set(&boxData.majorAxis, 0, 0, 1);    
  701.     Q3Vector3D_Set(&boxData.minorAxis, 1, 0, 0);    
  702.     boxData.boxAttributeSet = Q3AttributeSet_New();
  703.     faceColor.r = 0.9;
  704.     faceColor.g = 0.9;
  705.     faceColor.b = 0.2;
  706.     AttributeSet_AddDiffuseColor(boxData.boxAttributeSet, &faceColor);
  707.  
  708.     boxData.faceAttributeSet = NULL;
  709.     
  710.     
  711.     boxData.faceAttributeSet = malloc(6 * sizeof(TQ3AttributeSet));
  712.     
  713.     {
  714.         register unsigned long i;
  715.         
  716.         for (i = 0; i < 6; i++) {
  717.             boxData.faceAttributeSet[i] = NULL;
  718.         }
  719.     }
  720.     
  721.     if(gTextureEntries[0].shader != NULL)
  722.     {
  723.         
  724.         boxData.faceAttributeSet[0] = Q3AttributeSet_New();
  725.         
  726.         AttributeSet_AddSurfaceShader(
  727.             boxData.faceAttributeSet[0],
  728.             (TQ3SurfaceShaderObject *)&gTextureEntries[0].shader);
  729.     }
  730.     
  731.     if(gTextureEntries[1].shader != NULL)
  732.     {
  733.         
  734.         boxData.faceAttributeSet[1] = Q3AttributeSet_New();
  735.         
  736.         AttributeSet_AddSurfaceShader(
  737.             boxData.faceAttributeSet[1],
  738.             (TQ3SurfaceShaderObject *)&gTextureEntries[1].shader);
  739.         
  740.         Q3Object_Dispose(gTextureEntries[1].shader);
  741.     }
  742.     
  743.     boxData.faceAttributeSet[2] = Q3AttributeSet_New();
  744.     if(gTextureEntries[2].shader != NULL)
  745.     {
  746.         AttributeSet_AddSurfaceShader(
  747.             boxData.faceAttributeSet[2],
  748.             (TQ3SurfaceShaderObject *)&gTextureEntries[2].shader);
  749.     }
  750.     faceColor.r = 0.3;
  751.     faceColor.g = 0.9;
  752.     faceColor.b = 0.9;
  753.     AttributeSet_AddDiffuseColor(boxData.faceAttributeSet[2], &faceColor);
  754.     
  755.     boxData.faceAttributeSet[3] = Q3AttributeSet_New();
  756.     if(gTextureEntries[3].shader != NULL)
  757.     {
  758.         AttributeSet_AddSurfaceShader(
  759.             boxData.faceAttributeSet[3],
  760.             (TQ3SurfaceShaderObject *)&gTextureEntries[3].shader);
  761.     }
  762.     faceColor.r = 0.5;
  763.     faceColor.g = 0.5;
  764.     faceColor.b = 0.5;
  765.     AttributeSet_AddTransparencyColor(boxData.faceAttributeSet[3], &faceColor);
  766.     faceColor.r = 0.4;
  767.     faceColor.g = 0.4;
  768.     faceColor.b = 0.4;
  769.     AttributeSet_AddDiffuseColor(boxData.faceAttributeSet[3], &faceColor);
  770.     
  771.     if(gTextureEntries[4].shader != NULL)
  772.     {
  773.         
  774.         boxData.faceAttributeSet[4] = Q3AttributeSet_New();
  775.         
  776.         AttributeSet_AddSurfaceShader(
  777.             boxData.faceAttributeSet[4],
  778.             (TQ3SurfaceShaderObject *)&gTextureEntries[4].shader);
  779.     }
  780.     
  781.     if(gTextureEntries[5].shader != NULL)
  782.     {
  783.         
  784.         boxData.faceAttributeSet[5] = Q3AttributeSet_New();
  785.         
  786.         AttributeSet_AddSurfaceShader(
  787.             boxData.faceAttributeSet[5],
  788.             (TQ3SurfaceShaderObject *)&gTextureEntries[5].shader);
  789.     }
  790.     
  791.     boxThang = Q3Box_New(&boxData);
  792.     
  793.     model = Q3OrderedDisplayGroup_New();
  794.     Q3Group_AddObject(model, boxThang);    
  795.     
  796.     {
  797.         register unsigned long i;
  798.         
  799.         for (i = 0; i < 6; i++) {
  800.             if(boxData.faceAttributeSet[i] != NULL)
  801.             {
  802.                 Q3Object_Dispose(boxData.faceAttributeSet[i]);
  803.             }
  804.         }
  805.     }
  806.  
  807.     Q3Object_Dispose(boxData.boxAttributeSet);
  808.     free(boxData.faceAttributeSet);
  809.     Q3Object_Dispose(boxThang);
  810.     
  811.     return (model);    
  812. }
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821. /*===========================================================================*\
  822.  *
  823.  *    Routine:    BuildNURBCurve()
  824.  *
  825.  *    Comments:    
  826.  *
  827. \*===========================================================================*/
  828.     
  829. static TQ3GroupObject BuildNURBCurve(
  830.     void)
  831. {
  832.     TQ3ColorRGB            curveColor;
  833.  
  834.     TQ3GroupObject        model;
  835.     TQ3NURBCurveData        curveData;
  836.     TQ3GeometryObject    curveThang;
  837.     static TQ3RationalPoint4D    points[7] = {
  838.                             { 0.0,  0.0,  0.0, 1.0 },
  839.                             { 1.0,  1.0,  0.0, 1.0 },
  840.                             { 2.0,  0.0,  0.0, 1.0 },
  841.                             { 3.0,  1.0,  0.0, 1.0 },
  842.                             { 4.0,  0.0,  0.0, 1.0 },
  843.                             { 5.0,  1.0,  0.0, 1.0 },
  844.                             { 6.0,  0.0,  0.0, 1.0 },
  845.                         };
  846.     static float        knots[11] = {
  847.                             0, 0, 0, 0, 0.25, 0.5, 0.75, 1, 1, 1, 1
  848.                         };
  849.  
  850.     
  851.     curveData.order                     = 4;
  852.     curveData.numPoints                    = 7;
  853.     curveData.controlPoints                 = points;
  854.     curveData.knots                     = knots;
  855.     curveData.curveAttributeSet         = Q3AttributeSet_New();
  856.     
  857.     curveColor.r = 0.8;
  858.     curveColor.g = 0.2;
  859.     curveColor.b = 0.6;
  860.     AttributeSet_AddDiffuseColor(curveData.curveAttributeSet, &curveColor);
  861.     
  862.     curveThang = Q3NURBCurve_New(&curveData);
  863.     
  864.     model = Q3OrderedDisplayGroup_New();
  865.     Q3Group_AddObject(model, curveThang);    
  866.     Q3Object_Dispose(curveData.curveAttributeSet);
  867.     Q3Object_Dispose(curveThang);
  868.     
  869.     {
  870.         unsigned long         i;
  871.         TQ3MarkerData        markerData;
  872.         TQ3GeometryObject    markerThang;
  873.         TQ3ColorRGB            markerColor;
  874.         TQ3Bitmap            *bitmapPtr = &markerData.bitmap;
  875.         unsigned char        imageData[] = { 0x20, 0x50, 0x88, 0x50, 0x20 };
  876.     
  877.         bitmapPtr->image     = imageData;
  878.         bitmapPtr->width     = 5;
  879.         bitmapPtr->height     = 5;
  880.         bitmapPtr->rowBytes = 1;
  881.  
  882.  
  883.         Q3ColorRGB_Set(&markerColor, 0.1, 1.0, 0.6);
  884.         markerData.xOffset    = -2;
  885.         markerData.yOffset    = -2;
  886.         markerData.markerAttributeSet = Q3AttributeSet_New();
  887.         
  888.         AttributeSet_AddDiffuseColor(markerData.markerAttributeSet, 
  889.                                        &markerColor);    
  890.             
  891.         for (i = 0; i < curveData.numPoints; i++) {
  892.             Q3Point3D_Set(&markerData.location, 
  893.                           points[i].x / points[i].w,
  894.                           points[i].y / points[i].w,
  895.                           points[i].z / points[i].w);
  896.                 
  897.             markerThang = Q3Marker_New(&markerData);
  898.             Q3Group_AddObject(model, markerThang);
  899.             Q3Object_Dispose(markerThang);
  900.         }
  901.         
  902.         Q3Object_Dispose(markerData.markerAttributeSet);
  903.     }
  904.  
  905.     return (model);    
  906. }
  907.  
  908.  
  909. static TQ3GroupObject BuildNURBPatch(
  910.     void)
  911. {
  912.     TQ3GroupObject                        model;
  913.     TQ3NURBPatchData                    patchData;
  914.     TQ3GeometryObject                    patchThang;
  915.     TQ3NURBPatchTrimLoopData            trimLoops[2];
  916.     TQ3NURBPatchTrimCurveData            trimCurveZero, trimCurveOne;
  917.         
  918.     static TQ3RationalPoint4D    vertices[12] = {
  919.                             { -2.0, -2.0, 0, 1.0 },
  920.                             { -1.0, -2.0, 1, 1.0 },
  921.                             {  1.0, -2.0, 0, 1.0 },
  922.                             {  2.0, -2.0, 0, 1.0 },
  923.  
  924.                             { -2.0, -1.0, 0, 1.0 },
  925.                             { -1.0, -1.0, 1, 1.0 },
  926.                             {  1.0, -1.0, -1, 1.0 },
  927.                             {  2.0, -1.0, -1, 1.0 },
  928.  
  929.                             { -2.0, -0.0, 0, 1.0 },
  930.                             { -1.0, -0.0, 0, 1.0 },
  931.                             {  1.0, -0.0, 0, 1.0 },
  932.                             {  2.0, -0.0, 0, 1.0 },
  933.                         };
  934.                         
  935.     static float        vKnots[6] = {
  936.                             0, 0, 0, 1, 1, 1
  937.                         };
  938.     static float        uKnots[8] = {
  939.                             0, 0, 0, 0, 1, 1, 1, 1, 
  940.                         };
  941.  
  942.     static TQ3RationalPoint3D    trimPointsZero[5] = {
  943.                             { 0.1, 0.1, 1.0 },
  944.                             { 0.9, 0.1, 1.0 },
  945.                             { 0.4, 0.4, 1.0 },
  946.                             { 0.1, 0.4, 1.0 },
  947.                             { 0.1, 0.1, 1.0 },
  948.                         };
  949.             
  950.     static float        trimKnotsZero[9] = {
  951.                             0, 0, 0, 0, 0.5, 1, 1, 1, 1    
  952.                         };
  953.                         
  954.     static TQ3RationalPoint3D    trimPointsOne[5] = {
  955.                             { 0.3, 0.6, 1.0 },
  956.                             { 0.9, 0.6, 1.0 },
  957.                             { 0.4, 0.9, 1.0 },
  958.                             { 0.2, 0.9, 1.0 },
  959.                             { 0.3, 0.6, 1.0 },
  960.                         };
  961.             
  962.     static float        trimKnotsOne[9] = {
  963.                             0, 0, 0, 0, 0.5, 1, 1, 1, 1    
  964.                         };
  965.  
  966.                     
  967.     trimLoops[0].numTrimCurves     = 1;
  968.     trimLoops[0].trimCurves        = &trimCurveZero;    
  969.     
  970.     trimCurveZero.order            = 4;
  971.     trimCurveZero.numPoints        = 5;
  972.     trimCurveZero.knots            = trimKnotsZero;
  973.     trimCurveZero.controlPoints = trimPointsZero;
  974.     
  975.     trimLoops[1].numTrimCurves     = 1;
  976.     trimLoops[1].trimCurves        = &trimCurveOne;    
  977.     
  978.     trimCurveOne.order            = 4;
  979.     trimCurveOne.numPoints        = 5;
  980.     trimCurveOne.knots            = trimKnotsOne;
  981.     trimCurveOne.controlPoints     = trimPointsOne;
  982.                             
  983.     patchData.uOrder            = 4;
  984.     patchData.vOrder            = 3;
  985.     patchData.numColumns        = 4;
  986.     patchData.numRows            = 3;
  987.     patchData.uKnots            = uKnots;
  988.     patchData.vKnots            = vKnots;
  989.     patchData.controlPoints     = vertices;
  990. #if 0
  991.     patchData.numTrimLoops        = 2;
  992.     patchData.trimLoops         = trimLoops;
  993. #else
  994.     patchData.numTrimLoops        = 0;
  995.     patchData.trimLoops         = NULL;
  996. #endif  /*  ESCHER_VER_15  */
  997.  
  998.     
  999.     patchData.patchAttributeSet = Q3AttributeSet_New();
  1000.     {
  1001.         TQ3ColorRGB    patchColor;
  1002.         
  1003.         patchColor.r = 0.9;
  1004.         patchColor.g = 0.2;
  1005.         patchColor.b = 0.9;
  1006.         AttributeSet_AddDiffuseColor(patchData.patchAttributeSet, &patchColor);
  1007.     }
  1008.  
  1009.     
  1010.     patchThang = Q3NURBPatch_New(&patchData);
  1011.     
  1012.     model = Q3OrderedDisplayGroup_New();
  1013.     
  1014.     Q3Group_AddObject(model, patchThang);    
  1015.     Q3Object_Dispose(patchThang);
  1016.     Q3Object_Dispose(patchData.patchAttributeSet);
  1017.  
  1018.  
  1019.     {
  1020.         unsigned long         i;
  1021.         TQ3MarkerData        markerData;
  1022.         TQ3GeometryObject    markerThang;
  1023.         TQ3ColorRGB            markerColor;
  1024.         TQ3Bitmap            *bitmapPtr = &markerData.bitmap;
  1025.         unsigned char        imageData[] = { 0x20, 0x50, 0x88, 0x50, 0x20 };
  1026.     
  1027.         bitmapPtr->image     = imageData;
  1028.         bitmapPtr->width     = 5;
  1029.         bitmapPtr->height     = 5;
  1030.         bitmapPtr->rowBytes = 1;
  1031.  
  1032.  
  1033.         Q3ColorRGB_Set(&markerColor, 0.1, 1.0, 0.6);
  1034.         markerData.xOffset    = -2;
  1035.         markerData.yOffset    = -2;
  1036.         markerData.markerAttributeSet = Q3AttributeSet_New();
  1037.         
  1038.         AttributeSet_AddDiffuseColor(markerData.markerAttributeSet, 
  1039.                                        &markerColor);    
  1040.             
  1041.         for (i = 0; i < patchData.numColumns * patchData.numRows; i++) {
  1042.             Q3Point3D_Set(&markerData.location, 
  1043.                           vertices[i].x / vertices[i].w,
  1044.                           vertices[i].y / vertices[i].w,
  1045.                           vertices[i].z / vertices[i].w);
  1046.                                           
  1047.             markerThang = Q3Marker_New(&markerData);
  1048.             Q3Group_AddObject(model, markerThang);
  1049.             Q3Object_Dispose(markerThang);
  1050.         }
  1051.         
  1052.         Q3Object_Dispose(markerData.markerAttributeSet);
  1053.     }
  1054.     
  1055.     return (model);    
  1056. }
  1057.  
  1058.  
  1059. /*===========================================================================*\
  1060.  *
  1061.  *    Routine:    BuildCursor_NewQuadFace()
  1062.  *
  1063.  *    Comments:    Builds a quad face.
  1064.  *
  1065. \*===========================================================================*/
  1066.  
  1067. static TQ3MeshFace BuildCursor_NewQuadFace (
  1068.     TQ3GeometryObject    mesh,
  1069.     TQ3MeshVertex        vertex[],
  1070.     int                    index0,
  1071.     int                    index1,
  1072.     int                    index2,
  1073.     int                    index3)
  1074. {
  1075.     TQ3MeshFace            result;
  1076.     TQ3MeshVertex        v[4];
  1077.     
  1078.     v[0] = vertex[index0];
  1079.     v[1] = vertex[index1];
  1080.     v[2] = vertex[index2];
  1081.     v[3] = vertex[index3];
  1082.     
  1083.     result = Q3Mesh_FaceNew(mesh, 4, v, NULL);
  1084.     
  1085.     return (result);
  1086. }
  1087.  
  1088.  
  1089.  
  1090. /*===========================================================================*\
  1091.  *
  1092.  *    Routine:    BuildCursor_NewQuads()
  1093.  *
  1094.  *    Comments:    Builds a quadralateral from the given points.
  1095.  *
  1096. \*===========================================================================*/
  1097.  
  1098. static TQ3Status BuildCursor_NewQuads (
  1099.     TQ3GeometryObject    mesh,
  1100.     unsigned long        faceMask,
  1101.     float x0, float y0, float z0,
  1102.     float x1, float y1, float z1,
  1103.     float x2, float y2, float z2,
  1104.     float x3, float y3, float z3,
  1105.     float x4, float y4, float z4,
  1106.     float x5, float y5, float z5,
  1107.     float x6, float y6, float z6,
  1108.     float x7, float y7, float z7)
  1109. {
  1110.     TQ3Vertex3D            point;
  1111.     TQ3MeshVertex        vertex[8];
  1112.     
  1113.     /*
  1114.      *    Make the vertices
  1115.      */
  1116.     
  1117.     point.attributeSet = NULL;
  1118.     Q3Point3D_Set(&point.point,x0,y0,z0);
  1119.     if ((vertex[0] = Q3Mesh_VertexNew(mesh,&point)) == NULL) return (kQ3Failure);
  1120.     Q3Point3D_Set(&point.point,x1,y1,z1);
  1121.     if ((vertex[1] = Q3Mesh_VertexNew(mesh,&point)) == NULL) return (kQ3Failure);
  1122.     Q3Point3D_Set(&point.point,x2,y2,z2);
  1123.     if ((vertex[2] = Q3Mesh_VertexNew(mesh,&point)) == NULL) return (kQ3Failure);
  1124.     Q3Point3D_Set(&point.point,x3,y3,z3);
  1125.     if ((vertex[3] = Q3Mesh_VertexNew(mesh,&point)) == NULL) return (kQ3Failure);
  1126.     Q3Point3D_Set(&point.point,x4,y4,z4);
  1127.     if ((vertex[4] = Q3Mesh_VertexNew(mesh,&point)) == NULL) return (kQ3Failure);
  1128.     Q3Point3D_Set(&point.point,x5,y5,z5);
  1129.     if ((vertex[5] = Q3Mesh_VertexNew(mesh,&point)) == NULL) return (kQ3Failure);
  1130.     Q3Point3D_Set(&point.point,x6,y6,z6);
  1131.     if ((vertex[6] = Q3Mesh_VertexNew(mesh,&point)) == NULL) return (kQ3Failure);
  1132.     Q3Point3D_Set(&point.point,x7,y7,z7);
  1133.     if ((vertex[7] = Q3Mesh_VertexNew(mesh,&point)) == NULL) return (kQ3Failure);
  1134.     
  1135.     
  1136.     /*
  1137.      *    Make the faces
  1138.      */
  1139.     
  1140.     if (faceMask & (1<<0)) if (BuildCursor_NewQuadFace(mesh,vertex,0,3,2,1) == NULL) return (kQ3Failure);
  1141.     if (faceMask & (1<<1)) if (BuildCursor_NewQuadFace(mesh,vertex,4,7,6,5) == NULL) return (kQ3Failure);
  1142.     if (faceMask & (1<<2)) if (BuildCursor_NewQuadFace(mesh,vertex,4,0,1,5) == NULL) return (kQ3Failure);
  1143.     if (faceMask & (1<<3)) if (BuildCursor_NewQuadFace(mesh,vertex,7,6,2,3) == NULL) return (kQ3Failure);
  1144.     if (faceMask & (1<<4)) if (BuildCursor_NewQuadFace(mesh,vertex,4,7,3,0) == NULL) return (kQ3Failure);
  1145.     if (faceMask & (1<<5)) if (BuildCursor_NewQuadFace(mesh,vertex,5,1,2,6) == NULL) return (kQ3Failure);
  1146.     
  1147.     
  1148.     return (kQ3Success);
  1149. }
  1150.  
  1151.  
  1152.  
  1153. /*===========================================================================*\
  1154.  *
  1155.  *    Routine:    BuildCursor()
  1156.  *
  1157.  *    Comments:    
  1158.  *
  1159. \*===========================================================================*/
  1160.     
  1161. static TQ3GroupObject BuildCursor(
  1162.     void)
  1163. {
  1164.     TQ3GeometryObject    mesh            = NULL;
  1165.     TQ3GroupObject        group            = NULL;
  1166.     
  1167.     /*
  1168.      *    Create the mesh
  1169.      */
  1170.     
  1171.     mesh = Q3Mesh_New ();
  1172.     if (mesh == NULL) goto bail;
  1173.     
  1174.     Q3Mesh_DelayUpdates (mesh);
  1175.     
  1176.     
  1177.     /*
  1178.      *    Tip
  1179.      */
  1180.     
  1181.     /*** ??? WOULD THESE BE BETTER DONE WITH MESH CORNERS? ***/
  1182.     
  1183.     if (BuildCursor_NewQuads (    mesh,
  1184.                             (0<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5),
  1185.                              0.00,  0.00,  0.00,
  1186.                              0.00,  0.00,  0.00,
  1187.                              0.00,  0.00,  0.00,
  1188.                              0.00,  0.00,  0.00,
  1189.                              0.50,  0.25,  0.05,
  1190.                              0.50, -0.25,  0.05,
  1191.                              0.50, -0.25, -0.05,
  1192.                              0.50,  0.25, -0.05) != kQ3Success)
  1193.         goto bail;
  1194.     
  1195.     
  1196.     /*
  1197.      *    Tail
  1198.      */
  1199.     
  1200.     if (BuildCursor_NewQuads (    mesh,
  1201.                             (0<<0) | (1<<1) | (1<<2) | (1<<3) | (1<<4) | (1<<5),
  1202.                              0.50,  0.05,  0.05,
  1203.                              0.50, -0.05,  0.05,
  1204.                              0.50, -0.05, -0.05,
  1205.                              0.50,  0.05, -0.05,
  1206.                              1.00,  0.10,  0.10,
  1207.                              1.00, -0.10,  0.10,
  1208.                              1.00, -0.10, -0.10,
  1209.                              1.00,  0.10, -0.10) != kQ3Success)
  1210.         goto bail;
  1211.     
  1212.     Q3Mesh_ResumeUpdates (mesh);
  1213.     
  1214.     
  1215.     /*
  1216.      *    Build the group
  1217.      */
  1218.     
  1219.     group = Q3OrderedDisplayGroup_New ();
  1220.     if (group == NULL) goto bail;
  1221.     
  1222.     Q3Group_AddObject (group, mesh);
  1223.     Q3Object_Dispose (mesh);
  1224.     mesh = NULL;
  1225.     
  1226.     
  1227.     return (group);
  1228.     
  1229.     /*
  1230.      *    Error exit
  1231.      */
  1232.     
  1233.     bail:
  1234.     if (mesh    != NULL) Q3Object_Dispose (mesh);
  1235.     if (group    != NULL) Q3Object_Dispose (group);
  1236.     
  1237.     return (NULL);
  1238. }
  1239.  
  1240.  
  1241.  
  1242.  
  1243. /*===========================================================================*\
  1244.  *
  1245.  *    Routine:    BuildMesh()
  1246.  *
  1247.  *    Comments:    
  1248.  *
  1249. \*===========================================================================*/
  1250. /*
  1251.  
  1252.     Mesh (
  1253.         9 # nVertices
  1254.         { { -0.5,      0.5,    0.0 }, NULL },
  1255.         { { -0.5,    -0.5,    0.0 }, NULL },
  1256.         { {  0.0,    -0.5,     0.3 }, NULL },
  1257.         { {  0.5,     -0.5,     0.0 }, NULL },
  1258.         { {  0.5,      0.5,    0.0 }, NULL },
  1259.         { {  0.0,      0.5,    0.3 }, NULL },
  1260.         { { -0.4,      0.2,    0.0 }, NULL },
  1261.         { {  0.0,     0.0,    0.0 }, NULL },
  1262.         { { -0.4,     -0.2,    0.0 }, NULL },
  1263.         2 # nFaces
  1264.         1 # nContours
  1265.         4 0 1 2 5 # 0
  1266.         -3 6 7 8 # 2
  1267.         4 2 3 4 5 # 1
  1268.     )
  1269.  
  1270. */    
  1271. static TQ3GroupObject BuildMesh(
  1272.     void)
  1273. {
  1274.     TQ3ColorRGB            meshColor;
  1275.     TQ3GroupObject        model;
  1276.     extern void TextureGroup( TQ3GroupObject    theGroup) ;
  1277.     static TQ3Vertex3D    vertices[9] = {
  1278.         { { -0.5,      0.5,    0.0 }, NULL },
  1279.         { { -0.5,    -0.5,    0.0 }, NULL },
  1280.         { {  0.0,    -0.5,     0.3 }, NULL },
  1281.         { {  0.5,     -0.5,     0.0 }, NULL },
  1282.         { {  0.5,      0.5,    0.0 }, NULL },
  1283.         { {  0.0,      0.5,    0.3 }, NULL },
  1284.         { { -0.4,      0.2,    0.0 }, NULL },
  1285.         { {  0.0,     0.0,    0.0 }, NULL },
  1286.         { { -0.4,     -0.2,    0.0 }, NULL },
  1287.                         };
  1288.     static TQ3Param2D    verticesUV[9] = {
  1289.         {0.0, 1.0}, {0.0, 0.0}, {0.5, 0.0}, {1.0, 0.0},
  1290.         {1.0, 1.0}, {0.5, 1.0}, {0.1, 0.8}, {0.5, 0.5},
  1291.         {0.1, 0.4}};
  1292.         
  1293.     TQ3MeshVertex        meshVertices[9];
  1294.     TQ3GeometryObject    mesh;
  1295.     TQ3MeshFace            meshFace;
  1296.     TQ3AttributeSet    faceAttributes;
  1297.     unsigned long        i;
  1298.     
  1299.     mesh = Q3Mesh_New();
  1300.  
  1301.     Q3Mesh_DelayUpdates( mesh);
  1302.     
  1303.     for (i = 0; i < 9; i++) {
  1304.         TQ3AttributeSet vertexASet;
  1305.         
  1306.         meshVertices[i] = Q3Mesh_VertexNew(mesh, &vertices[i]);
  1307.         vertexASet = Q3AttributeSet_New();
  1308.         AttributeSet_AddSurfaceUV(vertexASet, &verticesUV[i]);
  1309.  
  1310.         Q3Mesh_SetVertexAttributeSet( mesh, meshVertices[i],vertexASet);
  1311.         Q3Object_Dispose(vertexASet);
  1312.     }
  1313.     
  1314.     faceAttributes = Q3AttributeSet_New();
  1315.     meshColor.r = 0.3;
  1316.     meshColor.g = 0.9;
  1317.     meshColor.b = 0.5;
  1318.     AttributeSet_AddDiffuseColor(faceAttributes, &meshColor);
  1319.  
  1320.     meshFace = Q3Mesh_FaceNew(mesh, 6, meshVertices, faceAttributes);
  1321.  
  1322.     Q3Mesh_FaceToContour( mesh,meshFace,Q3Mesh_FaceNew(mesh, 3, &meshVertices[6], NULL));
  1323.     
  1324.     Q3Mesh_ResumeUpdates( mesh);
  1325.     
  1326.     model = Q3OrderedDisplayGroup_New();
  1327.     
  1328.     Q3Group_AddObject(model, mesh);    
  1329.  
  1330.     Q3Object_Dispose(faceAttributes);
  1331.     Q3Object_Dispose(mesh);
  1332.     
  1333.  TextureGroup( model) ;
  1334.     return (model);    
  1335. }
  1336.  
  1337.  
  1338.